package yto.freemarker.springaop.connection;

import yto.freemarker.springaop.protocol.Protocol;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author dongxing
 **/
public class Connection {

    private Socket socket;
    private String host;
    private int port;
    private InputStream inputStream;
    private OutputStream outputStream;

    public Connection(String host, int port) {
        this.host = host;
        this.port = port;
    }

    /**
     * 往服务端发送数据
     *
     * @return
     */
    public Connection sendCommad(Protocol.Commad commad,byte[]...args) {
        connect();

        return this;
    }

    /**
     * 连接
     */
    public void  connect() {
        try {
            socket = new Socket(host, port);
            inputStream= socket.getInputStream();
            outputStream = socket.getOutputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
